/*
 * @Description: 员工订餐业务页面数据管理
 * @Author: tao.xie
 * @Date: 2019-03-19 11:46:47
 * @Last Modified by: tao.xie
 * @Last Modified time: 2019-03-19 16:56:07
 */
import { FAIL, REFUND, SUCCESS, TRADING } from '../constants/TradeState'
import { PAY, FREEZON, UNFREEZON } from '../constants/TradeType'
import { dateFtt } from 'vue-xiaobu-utils'

/**
 *根据交易状态返回详情数据元素集合
 *
 * @param {*} detailObj
 * @returns
 */
function getInfoListDataByState(detailObj) {
  let tradeType = detailObj.TRADE_TYPE

  switch (tradeType) {
    case PAY:
      // 订餐
      return getMealBookingInfoList(detailObj)
    case FREEZON:
      // 冻结
      return getFreezonInfoList(detailObj)
    case UNFREEZON:
      // 解冻
      return getUnFreezonInfoList(detailObj)
    default:
      break
  }
}

/**
 *订餐冻结
 *
 * @param {*} detailObj
 */
function getFreezonInfoList(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '冻结金额',
    infoValue: '-' + detailObj.PAY_FEE.toFixed(2),
    isInfoValueStress: true
  })
  copyinfolist.push({
    infoName: '冻结时间',
    infoValue: dateFtt('yyyy年MM月dd日 hh:mm:ss', detailObj.TRADE_TIME)
  })
  copyinfolist.push({
    infoName: '订单流水号',
    infoValue: detailObj.OUT_TRADE_NO
  })
  return copyinfolist
}
/**
 *订餐解冻
 *
 * @param {*} detailObj
 */
function getUnFreezonInfoList(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '解冻金额',
    infoValue: '+' + detailObj.PAY_FEE.toFixed(2),
    isInfoValueStress: true
  })
  copyinfolist.push({
    infoName: '解冻时间',
    infoValue: dateFtt('yyyy年MM月dd日 hh:mm:ss', detailObj.TRADE_TIME)
  })
  copyinfolist.push({
    infoName: '订单流水号',
    infoValue: detailObj.OUT_TRADE_NO
  })
  return copyinfolist
}

/**
 *订餐业务
 *
 * @param {*} detailObj
 * @returns
 */
function getMealBookingInfoList(detailObj) {
  let state = detailObj.STATE
  switch (state) {
    case FAIL:
      return getInfoListDataWhenFail(detailObj)
    case REFUND:
      return getInfoListDataWhenRefund(detailObj)
    case SUCCESS:
      return getInfoListDataWhenSuccess(detailObj)
    case TRADING:
      return getInfoListDataWhenTrading(detailObj)
    default:
      break
  }
}

/**
 *订餐失败的页面数据管理
 *
 * @param {*} detailObj
 */
function getInfoListDataWhenFail(detailObj) {
  let copyinfolist = []
  // TODO
  return copyinfolist.concat(getCommonListData(detailObj))
}

/**
 *订餐失败已退款的页面数据管理
 *
 * @param {*} detailObj
 */
function getInfoListDataWhenRefund(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '已退款',
    infoValue: '-' + detailObj.PAY_FEE.toFixed(2),
    isInfoValueStress: true
  })
  return copyinfolist.concat(getCommonListData(detailObj))
}

/**
 *订餐成功的页面数据管理
 *
 * @param {*} detailObj
 * @returns
 */
function getInfoListDataWhenSuccess(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '支付成功',
    infoValue: '-' + detailObj.PAY_FEE.toFixed(2),
    isInfoValueStress: true
  })
  return copyinfolist.concat(getCommonListData(detailObj))
}
/**
 *订餐待支付的页面数据管理
 *
 * @param {*} detailObj
 */
function getInfoListDataWhenTrading(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '待支付',
    infoValue: '-' + detailObj.PAY_FEE.toFixed(2),
    isInfoValueStress: true
  })
  return copyinfolist.concat(getCommonListData(detailObj))
}

/**
 *获取提现业务通用数据
 *
 * @param {*} detailObj
 * @returns
 */
function getCommonListData(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '消费时间',
    infoValue: dateFtt('yyyy年MM月dd日 hh:mm:ss', detailObj.TRADE_TIME)
  })
  copyinfolist.push({
    infoName: '订单流水号',
    infoValue: detailObj.OUT_TRADE_NO
  })
  return copyinfolist
}

export default getInfoListDataByState
